# coding=utf-8
"""
模板功能增强：Url管理器
    管理静态文件地址
    管理图片资源地址

    app.add_template_global(UrlManager.buildUrl, "buildUrl")
"""

import time
import application

class UrlManager(object) :
    def __init__(self):
        pass

    @staticmethod
    def buildUrl(path):
        return path

    @staticmethod
    def buildStaticUrl(path):
        release_version = application.app.config.get("RELEASE_VERSION")
        ver = "%s" % (int( time.time() )) if not release_version else release_version
        real_path = "/static" + str(path) + "?ver=" + ver
        return UrlManager.buildUrl(real_path)

    @staticmethod
    def buildImageUrl(path):
        app_config = application.app.config["APP"]
        url = app_config["domain"] + application.app.config["UPLOAD"]["prefix_url"] + path
        return url